#include <iostream>
#include <unordered_map>
#include <cmath>

bool is_prime(int num) {
    if (num < 2) {
        return false;
    }
    for (int i = 2; i <= static_cast<int>(std::sqrt(num)); i++) {
        if (num % i == 0) {
            return false;
        }
    }
    return true;
}

int closest_prime(int y) {
    int offset = 0;
    while (true) {
        if (is_prime(y + offset)) {
            return y + offset;
        } else if (is_prime(y - offset)) {
            return y - offset;
        }
        offset++;
    }
}

int main() {
    std::unordered_map<std::string, int> t {
        {"zero", 0}, {"one", 1}, {"two", 2}, {"three", 3}, {"four", 4},
        {"five", 5}, {"six", 6}, {"seven", 7}, {"eight", 8}, {"nine", 9}
    };

    std::string word1, word2, word3;
    std::cin >> word1 >> word2 >> word3;

    int y;
    try {
        y = std::stoi(std::to_string(t[word1]) + std::to_string(t[word2]) + std::to_string(t[word3]));
        std::cout << closest_prime(y) << std::endl;
    } catch (std::out_of_range& e) {
        std::cout << "Input number is out of range" << std::endl;
    } catch (std::invalid_argument& e) {
        std::cout << "Wrong input" << std::endl;
    }
    return 0;
}
